/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */
#include "Stdafx.h"
#include "resource.h"
#include "MFCHelperFuncs.h"

void MsgOutput (const TCHAR * Format,...)
{
     #define MAX_DBG_MSG_LEN  4096
     TCHAR Buf[MAX_DBG_MSG_LEN];

     va_list ap;
     va_start(ap, Format);

     _vsntprintf_s(Buf, MAX_DBG_MSG_LEN-1, _TRUNCATE, Format, ap);
     CString Title;
     Title.LoadString(IDS_ERRDLG_TITLE);
     MessageBox(NULL, Buf, Title, MB_OK|MB_ICONERROR|MB_TOPMOST);

     va_end(ap);
}


void MsgOutput (UINT ResID,...)
{
     CString Msg;
     Msg.LoadString(ResID);

     va_list ap;
     va_start(ap, ResID);

     MsgOutput(Msg.GetBuffer(0), ap);

     va_end(ap);
}

CString MakeString(UINT ResID)
{
     CString Msg;
     Msg.LoadString(ResID);
     return Msg;
}

void CheckItem(CMenu* SubMenu, LONG ItemId, bool Val)
{
     unsigned long Flag = MF_BYCOMMAND;
     if( Val ) Flag = Flag|MF_CHECKED;
     else      Flag = Flag|MF_UNCHECKED;

     SubMenu->CheckMenuItem(ItemId, Flag);
}

void EnableItem(CMenu* SubMenu, LONG ItemId, bool Val)
{
     unsigned long Flag = MF_BYCOMMAND;
     if( Val ) Flag = Flag|MF_ENABLED;
     else      Flag = Flag|MF_DISABLED|MF_GRAYED;

     SubMenu->EnableMenuItem(ItemId, Flag);
}
